//
//  FSTopTool.m
//  fanshu
//
//  Created by 李先生 on 16/4/14.
//  Copyright © 2016年 FS. All rights reserved.
//

#import "FSTopTool.h"
#define WH 44

@interface FSTopTool()

//字数显示
@property (nonatomic, weak) UILabel *textCount;


@end

@implementation FSTopTool

- (void)setupTopView
{
    
    //添加左边按钮
    UIButton *leftBtn = [self addOneButton:@"关闭"];
    leftBtn.frame = CGRectMake(5, 0, WH, WH);
    [leftBtn addTarget:self action:@selector(outLoginBtnClick) forControlEvents:UIControlEventTouchDown];
    [self addSubview:leftBtn];
    
    
    //添加右边按钮
    UIButton *rightBtn = [self addOneButton:@"发布"];
    CGFloat rightBtnX = ScreenWidth - WH -5;
    rightBtn.frame = CGRectMake(rightBtnX, 0, WH, WH);
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchDown];
    [self addSubview:rightBtn];
    
    //添加中间字数显示
    UILabel *textCount = [self addTextCountLabel];
    textCount.textAlignment =  NSTextAlignmentCenter;
    textCount.size = CGSizeMake(100, 100);
    textCount.centerX = self.centerX;
    textCount.centerY = self.height * 0.5;
    [self addSubview:textCount];
    self.textCount = textCount;
}

#pragma mark - 添加一个按钮
-(UIButton *)addOneButton:(NSString *)btnName
{
    //创建自定义按钮
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    //设置按钮状态
    [btn setTitle:btnName forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithRed:217/255.0 green:110/255.0 blue:93/255.0 alpha:1] forState:UIControlStateNormal];
    btn.titleLabel.font = setFont(15.0f);
    [btn setTitleColor:[UIColor colorWithRed:217/255.0 green:110/255.0 blue:93/255.0 alpha:0.5] forState:UIControlStateHighlighted];
    return btn;
}

#pragma mark - 添加字数显示
-(UILabel *)addTextCountLabel
{
    UILabel *textCount = [[UILabel alloc] init];
    textCount.text = @"0字";
    textCount.font = setFont(10.0f);
    textCount.textColor = [UIColor lightGrayColor];
    _textCount = textCount;
    return textCount;
}

#pragma mark - 点击了退出按钮
-(void)outLoginBtnClick
{
        if ([self.delegate respondsToSelector:@selector(FSTopToolOutLoginBtnClick)]) {
            [self.delegate FSTopToolOutLoginBtnClick];
        }
}

#pragma mark - 点击了发布按钮
-(void)rightBtnClick
{
    if (self.releaseOnClick) {
        self.releaseOnClick();
    }
}


@end
